Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/shadow #412

Merged
merged 6 commits into from
Sep 18, 2022
Merged

Feat/shadow #412

merged 6 commits into from
Sep 18, 2022

Conversation

csynineyang
Copy link
Contributor

Feature: support shadow type match regex #365:

  1. impl shadow match hint rule (insert/update/delete)
  2. support shadow type match regex (insert/update/delete)
    3、integrate test

Test Cases:
[hint mode]
/*A! shadow(shadow) */ INSERT INTO student(id,uid,score,name,nickname,gender,birth_year) values (1,3,100,'lilei','shadow test',1,1980);
/*A! shadow(shadow) */ SELECT * FROM student WHERE uid = 3;
/*A! shadow(shadow) */ UPDATE student SET score = 98 WHERE uid = 3;
/*A! shadow(shadow) */ DELETE FROM student WHERE uid = 3;

[regex mode]
INSERT INTO student(id,uid,score,name,nickname,gender,birth_year) values (1,2,100,'hanmeimei','shadow test',1,1981);
SELECT * FROM student WHERE uid = 2 AND name = 'hanmeimei';
UPDATE student SET score = 98 WHERE uid = 2 AND name = 'hanmeimei';
DELETE FROM student WHERE uid = 2 AND name = 'hanmeimei';

What this PR does:

Which issue(s) this PR fixes:

Fixes #

Special notes for your reviewer:

Does this PR introduce a user-facing change?:


csynineyang and others added 4 commits September 6, 2022 12:11
1. create shadow tables in init.sql & sharding.sql
2. hide shadow tables for "show tables" command
3. impl shadow match hint rule (only select)
4. support shadow type match regex (only select)
add integration test for shadow tables
1. impl shadow match hint rule (insert/update/delete)
2. support shadow type match regex (insert/update/delete)
3、integrate test
Comment on lines 96 to 105
/*
for _, sqlCase := range cases.ExShRegexCases {
for _, sense := range sqlCase.Sense {
if strings.Compare(strings.TrimSpace(sense), "shadow") == 0 {
params := strings.Split(sqlCase.Parameters, ",")
args := make([]interface{}, 0, len(params))
for _, param := range params {
k, _ := test.GetValueByType(param)
args = append(args, k)
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

无用的可以删掉

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

并不是无用,hint模式和regex模式的yaml配置只能生效一个,ExShHintCases是给hint模式的配置用的,ExShRegexCases是给regex模式的配置用的。默认配置是hint模式,所以就注释掉了ExShRegexCases,如果修改配置文件,就能用到这部分代码了

sense:
- shadow
expected:
type: "rowAffect"
value: 0
value: 1
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

加个换行吧

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

哪个地方?我是按case组来换行的,如果每个case都换行的,似乎不好看

//first shadow_rule, and then sharding_rule
if o.ShadowRule != nil && !matchShadow {
if matchShadow, err = (*optimize.ShadowSharder)(o.ShadowRule).Shard(stmt.Table, constants.ShadowDelete, stmt.Where, o.Args...); err != nil {
return nil, errors.Wrap(err, "calculate shards failed")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

calculate shadow shards failed 会不会更直接点

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

多个shadow规则并存时采用优先方案还是排它方案,相对来说,优先方案省事一些,而且逻辑上也比较清晰

@dongzl dongzl added the shadow Shadow table. label Sep 17, 2022
Copy link
Contributor

@jjeffcaii jjeffcaii left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@dongzl dongzl merged commit 3339536 into arana-db:feat/shadow Sep 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
shadow Shadow table.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants